package view.equipe;

import java.awt.GridLayout;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JPanel;

import server.models.Equipe;
import server.models.partie.IPartie;

public class EquipeContainerView extends JPanel implements Observer {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public EquipeContainerView(IPartie partie) {
		super();
		this.setLayout(new GridLayout(3,2));
		((Observable)partie).addObserver(this);
		for (Equipe equipe : partie.getListeEquipes()) {
			ajouterEquipeView(equipe);
		}
		
		this.repaint();
	}
	
	public void ajouterEquipeView(Equipe equipe) {
		this.add(new EquipeView(equipe));
		this.validate();
	}

	@Override
	public void update(Observable partie, Object equipe) {
		for (Equipe equipePartie : ((IPartie)partie).getListeEquipes()) {
			this.add(new EquipeView(equipePartie));
		}
		this.repaint();
	}
	
}
